package com.xy.mvvmdemo

import android.content.Intent
import android.content.pm.ActivityInfo
import android.os.Bundle
import android.os.PersistableBundle
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.xy.mvvmdemo.base.BaseActivity
import com.xy.mvvmdemo.bean.Test
import com.xy.mvvmdemo.bean.User
import com.xy.mvvmdemo.databinding.Activity3Binding
import com.xy.routerlibrary.Router

/**
 * @ClassName Activity3
 * @Author xy
 * @Date 2021/7/19 14:27
 * @Description Activity生命周期
 */
const val TAG = "Activity生命周期"
class Activity3:AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity3)
        Log.i(TAG, "onCreate: ")
        val activity3Binding = DataBindingUtil.setContentView<Activity3Binding>(this, R.layout.activity3)
        activity3Binding.lifecycleOwner = this
        activity3Binding.setVariable(BR.user,User())
        activity3Binding.commit.setOnClickListener {
            activity3Binding.nameText.setText("测试")
            Toast.makeText(this,activity3Binding.nameText.text,Toast.LENGTH_SHORT).show()
        }
        Toast.makeText(this,activity3Binding.nameText.text,Toast.LENGTH_SHORT).show()
    }




    override fun onRestart() {
        super.onRestart()
        Log.i(TAG, "onRestart: ")
    }

    override fun onResume() {
        super.onResume()
        Log.i(TAG, "onResume: ")
    }

    override fun onPause() {
        super.onPause()
        Log.i(TAG, "onPause: ")
    }

    override fun onStop() {
        super.onStop()
        Log.i(TAG, "onStop: ")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.i(TAG, "onDestroy: ")
    }

    override fun onSaveInstanceState(outState: Bundle, outPersistentState: PersistableBundle) {
        super.onSaveInstanceState(outState, outPersistentState)
        Log.i(TAG, "onSaveInstanceState: ")
    }

    override fun onRestoreInstanceState(savedInstanceState: Bundle) {
        super.onRestoreInstanceState(savedInstanceState)
        Log.i(TAG, "onRestoreInstanceState: 1")
    }

    override fun onRestoreInstanceState(
        savedInstanceState: Bundle?,
        persistentState: PersistableBundle?
    ) {
        super.onRestoreInstanceState(savedInstanceState, persistentState)
        Log.i(TAG, "onRestoreInstanceState: 2")
    }

    fun jump(view: View) {
        when(view.id){
            R.id.jumpToActivity2->{
                startActivity(Intent(this,Activity2::class.java))
            }
            R.id.screenChange->{
                requestedOrientation = if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE){
                    ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
                }else{
                    ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
                }
            }
            R.id.routerJump->{
//                Router.startActivity(this,"/modulemain/MainModuleActivity")
                ARouter.getInstance().build("/modulemain/MainModuleActivity").withString("route","路由跳转").navigation()
            }

            R.id.daiLi->{
                val newProxyInstance = MHookHelp.newProxyInstance(Test::class.java) as Test
                ToastUtils.showShort(newProxyInstance.test("测试"))

            }
        }
    }
}